package teaching.api;

import org.springframework.web.bind.annotation.*;
import teaching.pojo.Post;
import teaching.pojo.PostMain;
import teaching.service.PostService;
import teaching.util.Response;
import teaching.util.ResponseResult;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author:20201002983_郑雨蓓
 * Date: 2024/4/15
 * Description:
 */
@RestController
@RequestMapping("/post")
public class PostAPI {
    @Resource
    private PostService postService;


    //    查找所有主题帖
    @GetMapping("/allPost")
    public ResponseResult<List<Post>> getPosts() {
        List<Post> posts = postService.getAllPosts();
        return Response.createOkResp(posts);
    }

    //    根据主题帖查找某一主题帖对应的所有具体帖postMain
    @GetMapping("/postMainByPostId/{postId}")
    public ResponseResult<Object> getPostsMains(@PathVariable("postId") Long postId) {
        List<PostMain> postMains = postService.getPostsMains(postId);
        return Response.createOkResp(postMains);
    }

    @PostMapping("/createPost")
    public ResponseResult<Object> createPost(@RequestBody Post post) {
        int res = postService.addPost(post);
        return Response.createOkResp("发表成功");
    }

    @PostMapping("/createPostMain")
    public ResponseResult<Object> createPost(@RequestBody PostMain postMain) {
        int res = postService.addPostMain(postMain);
        return Response.createOkResp("发表成功");
    }
}
